using System;
using Sedge.Core.Utils;

namespace Sedge.Core.Configuration.Transport
{
	public class EmailTransport : ITransport
	{
		private string _to = String.Empty;
		private string _subject = String.Empty;
		private string _body = String.Empty;

		private Options _options;
		public Options Options
		{
			get { return _options; }
			set
			{
				_options = value;
				if (_options != null)
				{
					_to = _options.GetGeneralOption("To", "to");
					_subject = _options.GetGeneralOption("Subject", "subject");
					_body = _options.GetGeneralOption("Body", "body");
				}
			}
		}

		public bool CanSend(Suite suite)
		{
			return !String.IsNullOrEmpty(_to);
		}

		public void Send(Suite suite, string path)
		{
			if (!CanSend(suite))
				return;
			
			MAPI mapi = new MAPI();
			mapi.AddRecipientTo(_to);
			mapi.AddAttachment(path);
			mapi.SendMailPopup(_subject, _body);
		}
	}
}